package me.shiqiang.im.linsteners;

import com.corundumstudio.socketio.annotation.OnEvent;
import me.shiqiang.im.enums.MessageCmd;
import me.shiqiang.im.msg.SyncReq;
import me.shiqiang.im.redis.RedisKey;
import me.shiqiang.im.util.RedisPipelineProcessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.ConcurrentLinkedQueue;

/**
 * 消息同步确认
 * Created by John on 2018/9/12
 */
@Component("SyncMsgConfirmListener")
public class SyncMsgConfirmListener extends Listener {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    ConcurrentLinkedQueue<RedisPipelineProcessor> queue;

    @OnEvent(MessageCmd.SYNC_MSG_CONFIRM)
    public void onSyncMsgConfirm(SyncReq msg) {
        queue.add(connection ->
                connection.zRemRangeByScore(
                        RedisKey.clientMsgQueue(msg.getUserId().toString()).getBytes(), 0, msg.getSyncKey()));
    }
}
